package com.sunda.spmswms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunda.spmswms.entity.SapDeliveryNoteLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.ClobTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Wayne
 * @since 2021-04-13
 */
@Mapper
public interface SapDeliveryNoteLogMapper extends BaseMapper<SapDeliveryNoteLog> {

    @Select("SELECT LOG.UUID AS \"uuid\",\n" +
            "       LOG.DOCUMENT_NUMBER AS \"documentNumber\",\n" +
            "       LOG.USER_ID AS \"userId\",\n" +
            "       U.LAST_NAME AS \"userName\",\n" +
            "       LOG.COMMENTS AS \"comments\",\n" +
            "       LOG.CREATE_TIME AS \"createTime\",\n" +
            "       LOG.LOG_AUTO_ID AS \"logAutoId\",\n" +
            "       LOG.REMARK AS \"remark\"\n" +
            "FROM SAP_DELIVERY_NOTE_LOG LOG\n" +
            "    LEFT JOIN SPMS_USER U ON LOG.USER_ID = U.WORK_CODE\n" +
            "WHERE LOG.DOCUMENT_NUMBER = #{documentNumber}\n" +
            "ORDER BY LOG.LOG_AUTO_ID DESC ")
    @Results({
            @Result(column = "remark", property = "remark", javaType = String.class,
                    jdbcType = JdbcType.CLOB, typeHandler = ClobTypeHandler.class)
    })
    List<Map<String, Object>> getDocumentLogs(String documentNumber);
}
